﻿/**
 *	html/pem_login.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-07		create the file
 */

/**
 *	create login panel
 *
 *	@panel_main			[in] the main panel object
 */
var g_panel_login;
function create_login_panel( panel_main )
{
    var titleHtml = "<div style=\"text-align:center\">" +
                        "<b>" +
                            "<font size=\"8\" face=\"宋体\">" +
                                "欢迎登录 TPSP-3000-SC动环系统" +
                            "</font>" +
                        "</b>" +
                    "</div>";

    g_panel_login = new Ext.form.Panel
    ({
         id:"panel_login",
         height:"100%",
         width:"100%",
         store:g_user,
         layout:{type:"anchor"},
         items:[
             {border:false, anchor:"100% 40%"},
             {xtype:"label", html:titleHtml},
             {border:false, anchor:"100%", height:20},
             {xtype:"fieldset", border:false, layout:{type:"hbox", align:"middle", pack:"center"}, width:"100%",
              items:[{name:"account", xtype:"textfield", fieldLabel:"用户名", labelWidth:60, width:250}]},
             {xtype:"fieldset", border:false, layout:{type:"hbox", align:"middle", pack:"center"}, width:"100%",
              items:[{name:"password", xtype:"textfield", fieldLabel:"登录密码", inputType:"password", labelWidth:60, width:250}]},
             {xtype:"fieldset", layout:{type:"hbox", align:"middle", pack:"center"}, border:false,
                 items:[
                     {xtype:"button", text:"登录", handler:on_user_login, width:60, margin:10},
                     {xtype:"button", text:"新增用户", width:60, margin:10},
                 ]
             },
         ],
    });

    g_panel_login.loadRecord( g_user.getAt( 0 ) );
    g_panel_login.show();

    g_panel_login.setWidth( Ext.getBody().getWidth() );
    g_panel_login.setHeight( Ext.getBody().getHeight() - 2 );
    panel_main.panel_login = g_panel_login;

    panel_main.add( g_panel_login );
}

function on_user_login()
{
    g_panel_login.updateRecord();
    var record		= g_panel_login.getRecord();
    var	account 	= record.get( "account" );
    var password	= record.get( "password" );

    user_login( account, password );
}
